﻿using System;
using System.Collections;
using System.Web;
using BLL;
using Model;

namespace GeniusAdminWebApplication
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User u = (User)HttpContext.Current.Session["admin"];
            if (u != null)
            {
                HttpContext.Current.Session.Remove("admin");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = TextBox1.Text.Trim();
            string password = TextBox2.Text.Trim();
            AdminService adminService = new AdminService();
            Hashtable ht = adminService.login(username, password);
            string result = (string)ht["result"];
            string message = (string)ht["message"];
            if (result == "0")
            {
                Response.Write("<script>alert('登陆失败: " + message + "')</script>");
            }
            else
            {
                HttpContext.Current.Session.Add("admin", ht["admin"]);
                Response.Redirect("index.aspx");
            }
        }

    }
}